// run: $exec < input
// opt: 0
// flag: -g
#include <iostream>
#include <string>

int const maxn = 1000006;
int const len = 8;
unsigned long long const diff = 100000000;
unsigned long long comp[200];
int lc;
bool not_prime[maxn];
unsigned long long prime[maxn];
unsigned long long l;
int tot;
std::string s;
int n;

void init_prime()
{
	for (int i = 2; i < maxn; i++) {
		if (not_prime[i]) continue;
		prime[tot++] = i;
		for (int j = i * 2; j < maxn; j += i)
			not_prime[j] = true;
	}
}

bool can_mod(unsigned long long p)
{
	unsigned long long now = comp[0];
	for (int i = 1; i < lc; i++) {
		now %= p;
		now = now * diff + comp[i];
	}
	return !(now % p);
}

void trans()
{
	lc = 0;
	if (n % len) s = std::string(len - (n % len), '0') + s;
	n = s.size();
	for (int i = 0; i < n; i += len, lc++) {
		comp[lc] = 0;
		for (int j = 0; j < len; j++) comp[lc] = comp[lc] * 10 + s[i + j] - '0';
	}
}

int main()
{
	init_prime();
	while (std::cin >> s >> l && l) {
		n = s.size();
		trans();
		bool good = true;
		for (int i = 0; i < tot && prime[i] < l; i++) {
			if (can_mod(prime[i])) {
				std::cout << "BAD ";
				std::cout << prime[i] << '\n';
				good = false;
				break;
			}
		}
		if (good) std::cout << "GOOD\n";
	}
}

